package ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.devicecontroller.factories.imp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import net.wimpi.modbus.io.ModbusTransport;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.persistence.DeviceDAO;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.devicecontroller.factories.ConnectionHandlerFactory;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.devicecontroller.factories.DeviceManagerFactory;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.devicecontroller.imp.AutomaticConnectionHandler;

@Component("AutomaticConnectionHandlerFactory")
public class AutomaticConnectionHandlerFactory implements
		ConnectionHandlerFactory {


	@Autowired(required=true)
	private DeviceManagerFactory deviceManagerFactory;
	@Autowired(required=true)
	private DeviceDAO deviceDAO;
	
	@Override
	public AutomaticConnectionHandler create(ModbusTransport modbusTransport) {
		AutomaticConnectionHandler ret = new AutomaticConnectionHandler();
		ret.setIncoming(modbusTransport);
		ret.setDeviceManagerFactory(deviceManagerFactory);
		ret.setDeviceDAO(deviceDAO);
		return ret;
	}

	/**
	 * @return the deviceManagerFactory
	 */
	public DeviceManagerFactory getDeviceManagerFactory() {
		return deviceManagerFactory;
	}

	/**
	 * @param deviceManagerFactory the deviceManagerFactory to set
	 */
	public void setDeviceManagerFactory(DeviceManagerFactory deviceManagerFactory) {
		this.deviceManagerFactory = deviceManagerFactory;
	}

	/**
	 * @return the deviceDAO
	 */
	public DeviceDAO getDeviceDAO() {
		return deviceDAO;
	}

	/**
	 * @param deviceDAO the deviceDAO to set
	 */
	public void setDeviceDAO(DeviceDAO deviceDAO) {
		this.deviceDAO = deviceDAO;
	}

}
